home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / programming / misc / toolboxsas.lha / Toolbox / lib / include / Sets.h < prev    next >
Encoding:
C/C++ Source or Header  |  1995-02-15  |  2.7 KB  |  96 lines

  1. #ifndef yySets
  2. #define yySets
  3.  
  4. /* $Id: Sets.h,v 1.7 1992/08/07 14:36:33 grosch rel $ */
  5.  
  6. /* $Log: Sets.h,v $
  7.  * Revision 1.7  1992/08/07  14:36:33  grosch
  8.  * layout changes
  9.  *
  10.  * Revision 1.6  1992/02/06  09:29:54  grosch
  11.  * fixed bug: stdio and ANSI C
  12.  *
  13.  * Revision 1.5  1991/11/21  14:25:34  grosch
  14.  * new version of RCS on SPARC
  15.  *
  16.  * Revision 1.4  91/07/17  17:23:38  grosch
  17.  * introduced ARGS trick for ANSI compatibility
  18.  *
  19.  * Revision 1.3  90/07/04  14:34:05  grosch
  20.  * introduced conditional include
  21.  *
  22.  * Revision 1.2  89/12/08  17:25:03  grosch
  23.  * complete redesign in order to increase efficiency
  24.  *
  25.  * Revision 1.1  89/01/09  17:29:42  grosch
  26.  * added functions Size, Minimum, and Maximum
  27.  *
  28.  * Revision 1.0  88/10/04  11:44:45  grosch
  29.  * Initial revision
  30.  *
  31.  */
  32.  
  33. /* Ich, Doktor Josef Grosch, Informatiker, Sept. 1987 */
  34.  
  35.  
  36. #include "ratc.h"
  37. #include <stdio.h>
  38.  
  39.  
  40. #define BitsPerBitset     32
  41. #define LdBitsPerBitset   5
  42. #define MaskBitsPerBitset 0x0000001f
  43.  
  44. #define IsElement(Elmt,Set)       ((int)((Set)->BitsetPtr[(Elmt) >> LdBitsPerBitset] << ((Elmt) & MaskBitsPerBitset)) < 0)
  45. #define Size(Set)                 ((Set)->MaxElmt)
  46. #define Select(Set)               Minimum(Set)
  47. #define IsNotEqual(Set1,Set2)     (!IsEqual(Set1,Set2))
  48. #define IsStrictSubset(Set1,Set2) (IsSubset(Set1,Set2) && IsNotEqual(Set1,Set2))
  49.  
  50.  
  51. typedef long BITSET;
  52.  
  53. typedef struct {
  54.                 cardinal  MaxElmt;
  55.                 cardinal  LastBitset;
  56.                 BITSET   *BitsetPtr;
  57.                 short     Card;
  58.                 cardinal  FirstElmt;
  59.                 cardinal  LastElmt;
  60.                } tSet;
  61.  
  62.  
  63. void MakeSet(tSet *Set, cardinal MaxSize);
  64. void ReleaseSet(tSet *Set);
  65. void Union(tSet *Set1, tSet *Set2);
  66. void Difference(tSet *Set1, tSet *Set2);
  67. void Intersection(tSet *Set1, tSet *Set2);
  68. void SymDiff(tSet *Set1, tSet *Set2);
  69. void Complement(tSet *Set);
  70. void Include(tSet *Set, cardinal Elmt);
  71. void Exclude(tSet *Set, cardinal Elmt);
  72. cardinal Card(tSet *Set);
  73. /* cardinal Size(tSet *Set); */
  74. cardinal Minimum(tSet *Set);
  75. cardinal Maximum(tSet *Set);
  76. /* cardinal Select(tSet *Set); */
  77. cardinal Extract(tSet *Set);
  78. bool IsSubset(tSet *Set1, tSet *Set2);
  79. /* bool IsStrictSubset(tSet *Set1, tSet *Set2); */
  80. bool IsEqual(tSet *Set1, tSet *Set2);
  81. /* bool IsNotEqual(tSet *Set1, tSet *Set2); */
  82. /* bool IsElement(cardinal Elmt, tSet *Set); */
  83. bool IsEmpty(tSet *Set);
  84. bool Forall(tSet *Set, bool (* Proc)());
  85. bool Exists(tSet *Set, bool (* Proc)());
  86. bool Exists1(tSet *Set, bool (* Proc)());
  87. void Assign(tSet *Set1, tSet *Set2);
  88. void AssignElmt(tSet *Set, cardinal Elmt);
  89. void AssignEmpty(tSet *Set);
  90. void ForallDo(tSet *Set, void (* Proc)());
  91. void ReadSet(FILE *File, tSet *Set);
  92. void WriteSet(FILE *File, tSet *Set);
  93. void InitSets(void);
  94.  
  95. #endif
  96.